package com.wnxy.admin.controller;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.dto.MaintenanceTaskDto;
import com.wnxy.admin.dto.PageResult;
import com.wnxy.admin.entity.AlarmSettings;
import com.wnxy.admin.vo.TaskVo;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.wnxy.admin.entity.MaintenanceTasks;
import com.wnxy.admin.service.IMaintenanceTasksService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/maintenance-tasks")
public class MaintenanceTasksController {

    private final IMaintenanceTasksService maintenanceTasksServiceImpl;
    public MaintenanceTasksController(IMaintenanceTasksService maintenanceTasksServiceImpl){
        this.maintenanceTasksServiceImpl = maintenanceTasksServiceImpl;
    }

    /*
     *  数据导出
     * */
    @GetMapping("/export")
    public void export(ModelMap map,
                       HttpServletRequest request,
                       HttpServletResponse response) {
        List<MaintenanceTasks> maintenanceTasksList = maintenanceTasksServiceImpl.list();
        ExportParams params = new ExportParams("任务列表", "任务列表", ExcelType.XSSF);
        map.put(NormalExcelConstants.DATA_LIST, maintenanceTasksList);
        map.put(NormalExcelConstants.CLASS, MaintenanceTasks.class);
        map.put(NormalExcelConstants.PARAMS, params);
        map.put(NormalExcelConstants.FILE_NAME, "maintenanceTasksList");
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
    }

    /*
     *  查看任务
     * */
    @PostMapping("/viewTask")
    public ResponseResult viewTask(@RequestBody MaintenanceTasks maintenanceTasks) {
        TaskVo taskVo = maintenanceTasksServiceImpl.viewTask(maintenanceTasks);
        return ResponseResult.ok(taskVo);
    }

    /*
     *  退回任务
     * */
    @PutMapping("/ReturnTask")
    public ResponseResult ReturnTask(@RequestBody MaintenanceTasks maintenanceTasks) {
        maintenanceTasksServiceImpl.ReturnTask(maintenanceTasks);
        return ResponseResult.ok();
    }

    /*
    *  处理任务
    * */
    @PutMapping("/processingTasks")
    public ResponseResult processingTasks(@RequestBody MaintenanceTasks maintenanceTasks) {
        maintenanceTasksServiceImpl.processingTasks(maintenanceTasks);
        return ResponseResult.ok();
    }

    /*
    *  删除管理任务
    * */
    @DeleteMapping("/removeBatchMaintenanceTask")
    public ResponseResult removeBatchMaintenanceTask(@RequestBody List<Long> maintenanceTaskIds) {
        maintenanceTasksServiceImpl.removeBatchMaintenanceTask(maintenanceTaskIds);
        return ResponseResult.ok();
    }

    /*
    * 编辑管理任务
    * */
    @PutMapping("/editMaintenanceTask")
    public ResponseResult editMaintenanceTask(@RequestBody MaintenanceTasks maintenanceTasks) {
        maintenanceTasksServiceImpl.editMaintenanceTask(maintenanceTasks);
        return ResponseResult.ok();
    }

    /*
     *  查询管理任务(分页)
     * */
    @GetMapping("/queryAlarmTask")
    public ResponseResult queryAlarmTask(@ModelAttribute MaintenanceTaskDto maintenanceTaskDto) {
        PageResult page = maintenanceTasksServiceImpl.queryAlarmTask(maintenanceTaskDto);
        return ResponseResult.ok(page);
    }

}
